package web.base.system.dao;

import blue.jdbc.core.BaseDao;
import blue.jdbc.core.Expression;
import blue.jdbc.core.OrderBy;
import org.springframework.stereotype.Repository;
import web.base.system.model.Role;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-02
 */
@Repository
public class RoleDao extends BaseDao<Role>
{
	public RoleDao()
	{
	}

	@Override
	protected void query(Expression exp, Role param)
	{
		if (param != null)
		{
			if (param.getCode() != null && !param.getCode().isEmpty())
			{
				param.setCode("%" + param.getCode() + "%");
				exp.add("a.code like :code");
			}
			if (param.getName() != null && !param.getName().isEmpty())
			{
				param.setName("%" + param.getName() + "%");
				exp.add("a.name like :name");
			}
			if (param.getState() != null)
			{
				exp.add("a.state=:state");
			}
		}
	}

	@Override
	protected void orderBy(OrderBy order, Role param)
	{
		order.add("id desc");
	}
}
